﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using SuperMarketManagement.Entity;

namespace SuperMarketManagement.DAO.NHibernate
{
    public class ProductBlockDAO : GenericDAO<ProductBlock, long>
    {
        public ProductBlockDAO(ISession session)
            : base(session)
        {
        }
        public IList<ProductBlock> GetAvailablesByProductId(long autoId)
        {
            return Session
                    .CreateCriteria(typeof(ProductBlock))
                    .Add(Expression.And(
                        Expression.Eq("Product.AutoId", autoId),
                        Expression.Ge("AvailableUnits", 0.0)))
                    .AddOrder(Order.Asc("PurchasedDate"))
                    .List<ProductBlock>();
        }
    }
}
